<template>
	<view class="xubao-footer">
		<view class="xubao-footer-box">
			<view class="footer-item" :class="{'active': currentTabIndex == 0}" @click.stop="toggleTab(0)">
				
				<image class="footer-image" src="@/static/xubao/work_active.png" v-if="currentTabIndex == 0"></image>
				<image class="footer-image" src="@/static/xubao/work.png" v-else></image>
				<view class="footer-text">任务清单</view>
			</view>
			<view class="footer-item" :class="{'active': currentTabIndex == 1}" @click.stop="toggleTab(1)">
				<image class="footer-image" src="@/static/xubao/yuyue_active.png" v-if="currentTabIndex == 1"></image>
				<image class="footer-image" src="@/static/xubao/yuyue.png" v-else></image>
				<view class="footer-text">预约清单</view>
			</view>
			<view class="footer-item" :class="{'active': currentTabIndex == 2}" @click.stop="toggleTab(2)">
				
				<image class="footer-image" src="@/static/xubao/kpi_active.png" v-if="currentTabIndex == 2"></image>
				<image class="footer-image" src="@/static/xubao/kpi.png" v-else></image>
				<view class="footer-text">KPI报表</view>
			</view>
			<view class="footer-item" :class="{'active': currentTabIndex == 3}" @click.stop="toggleTab(3)">
				
				<image class="footer-image" src="@/static/xubao/data_active.png" v-if="currentTabIndex == 3"></image>
				<image class="footer-image" src="@/static/xubao/data.png" v-else></image>
				<view class="footer-text">数据处理</view>
			</view>
		</view>

		<view class="safe-area-height" :style="{'height': safeArea.bottom + 'px'}"></view>
	</view>
</template>

<script>
	export default {
		props: {
			tabIndex: {
				default: 0
			}
		},
		data() {
			return {
				currentTabIndex: this.tabIndex,
				safeArea: {},
			}
		},
		onReady() {
			const systemInfo = uni.getSystemInfoSync();
			let safeArea = systemInfo.safeAreaInsets;
			this.safeArea = safeArea;
		},
		methods: {
			toggleTab(index) {
				this.currentTabIndex = index;
				this.$emit("handleTabToggle", index);
			},
		},
	}
</script>

<style lang="less">
	.xubao-footer {
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: #fff;
		border-top: 1px solid #e7e7e7;

		.xubao-footer-box {
			width: 100%;
			height: 48px;
			display: flex;
			align-items: center;

			.footer-item {
				flex: 1;
				min-width: 0;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				.footer-image{
					width: 24px;
					height: 24px;
				}
				.footer-icon {
					font-size: 24px;
					color: #999;
				}

				.footer-text {
					font-size: 10px;
					color: #999;
					margin-top: 2px;
				}

				&.active {
					.footer-icon {
						font-size: 24px;
						color: #008aff;
					}

					.footer-text {
						font-size: 10px;
						color: #008aff;
					}
				}
			}
		}

	}
</style>
